#include "common.h"

#define MAX_FROM_LEN 260
#define MAX_TO_LEN 2048
#define MAX_CC_LEN 2048
#define MAX_BCC_LEN 2048
#define MAX_FN_LEN 260
#define MAX_PATH_LEN 260
#define MAX_SUBJ_LEN 1000

char mail_data_path[MAX_PATH_LEN + 1];
char mail_temp_path[MAX_PATH_LEN + 1];
char attach_down_path[MAX_PATH_LEN + 1];
char mail_password_path[MAX_PATH_LEN + 1];

typedef struct attachment {
	char loc_filename[MAX_FN_LEN + 1];
	char loc_name[MAX_FN_LEN + 1];
	char path_of_sender[MAX_PATH_LEN + 1];  
	struct attachment *next;
} Attachment;

typedef struct mail_info {
	unsigned long int source_ip;
	unsigned long int dest_ip;
	unsigned short int source_port;
	unsigned short int dest_port;
	unsigned long int start_seq;
	unsigned char client_mac[MAC_LEN + 1];
	int mail_type;  //邮件类型
	unsigned long int mail_length;  
	int count; 
	int is_complished;  //邮件是否处理完毕
	int is_proce_mail;
	char username[MAX_UN_LEN + 1];
	char passwd[MAX_PW_LEN + 1];
	char *mail_data;  //存放请求服务器的数据包的内容
	char *recive_data;//存放服务器响应的数据包的内容 即OK包的内容
	char cookie_data[MAX_COOKIE_LEN + 1];
	char connect_id[MAX_ID_LEN + 1];
	char * mail_id;//用于与附件的连接
	unsigned long int recive_length;  //真正的的数据长度
	unsigned long int ok_length;  //整个OK包的长度
	unsigned long int http_seq; //OK 包的开始确认号
	char from[MAX_FROM_LEN + 1];
	char to[MAX_TO_LEN + 1];
	char cc[MAX_CC_LEN + 1]; //抄送
	char bcc[MAX_BCC_LEN + 1];//秘密抄送
	char subject[MAX_SUBJ_LEN + 1];
	char url[256];
	char *content;//邮件内容
	char sent_time[MAX_TIME_LEN + 1];
	int num_of_attach;//该邮件的附件个数
	int mail_num;
	Attachment *attach; //连接附件
	char save_path[MAX_PATH_LEN + 1]; //邮件存放的路径
	char ID_str[MAX_ID_LEN + 1];
	char path_of_here[MAX_PATH_LEN + 1];
	char *attach_name;
	int     is_writing;
	unsigned long int   source_seq;
	unsigned long int   ack_seq;
	int   is_ok_chunked;  //判断是否为chunked包
	int   ok_gzip;
	int   is_have_contentlength;
	int   attach_len;
	struct mail_info *prev;
	struct mail_info *next;
} Mail_info;

typedef struct attach_info {
	int packet_type;// new
	unsigned long int source_ip;
	unsigned long int dest_ip;
	unsigned short int source_port; //发送端口号
	unsigned short int dest_port;  //目的端口号
	unsigned long int start_seq;  //请求包开始的确认号
	unsigned long int http_seq;  //附件OK包开始确认号
	unsigned long int ok_start_seq;
	int attach_type; //附件类型
	char ID_str[MAX_ID_LEN + 1];  //附件ID 用于连接对应的邮件
	char *path_of_sender;
	char path_of_here[MAX_PATH_LEN + 1];//附件存放路径
	char attach_name[MAX_PATH_LEN + 1]; // 附件别名
	char attname[MAX_PATH_LEN + 1];  //附件的文件名字
	int ok_gzip;
	int is_ok_chunked;  //判断是否为chunked包
	char *ok_data;
	unsigned long int ok_len; 
	int is_complished;
	int is_writing;  //附件是否写完 初始为0
	int is_get_ok;
	int ok_pause;
	unsigned long int recive_length; // OK 包中真正的数据长度
	unsigned long int ok_length;  //整个OK包的长度 
	char *recive_data; //存放服务器响应的数据包的内容 即OK包的内容
	struct attach_info *prev;
	struct attach_info *next;
} Attach_info;

typedef struct mail_table {
	Mail_info *head;
	int count;
} MailTable;

typedef struct attach_table {
	Attach_info *head;
	Attach_info *tail;
	int count;
} AttachTable;

MailTable mail_tab;
AttachTable attach_tab;

